var form,$,table;
layui.use(['form','jquery','table'],function() {
    form = layui.form;
    $ = layui.jquery;
    table = layui.table;

    //查询操作日志
    getData('', '', '', '');
});


function getData(trueName, remark, type, createDate){
    $.ajax({
        url: '/microcircle/selLog',
        type: 'post',
        dataType: 'json',
        data: {
            'trueName': trueName ,
            'remark': remark,
            'type': type,
            'createDate': createDate,
        },
        success: function (item) {
            console.log(item.data);
            getTable(item.data);
        }
    })
}

//表数据
function getTable(data){
    table.render({
        elem: '#demo' ,
        data: data,
        toolbar:'#toolutil',
        page:{
            layout:['count','prev','page','next','limit','skip','refresh'],
            limits:[10,20,30],
        },
        cols:[[
            {type:'checkbox',},
            {title:'序号', align:'center' ,width:70, templet:function (data) {
                    return data.LAY_INDEX;
                }},
            {field:'trueName',title:'管理员名称',align:'center'},
            {field:'remark',title:'操作列表',align:'center'},
            {field:'createDate',title:'执行时间',align:'center'},
            {field:'type',title:'操作类型',align:'center',templet: function (data) {
                    var type;
                    if (data.type == 2){
                        type = "添加";
                    }
                    if (data.type == 3){
                        type = "删除";
                    }
                    if (data.type == 4){
                        type = "修改";
                    }
                    if (data.type == 5){
                        type = "查看";
                    }
                    return type;
                }},
            {field:'',title:'备注',align:'center',templet:function () {
                    return "无内容";
                }},
            {field:'',title:'操作',align:'center',templet:function(data){
                    return "<a class='operation' href='javascript:del(\"" + data.logId + "\");'>删除</a>"
                }},
        ]]
    });
};

//返回
function backOff() {
    var arr = localStorage.getItem("numArr");
    var numArr = arr.split(",");
    numArr.pop();
    window.parent.layui.element.tabChange('tab',numArr[numArr.length - 1]);
    localStorage.setItem("numArr",numArr);
}

//刷新
function load() {
    location.reload();
};

//搜索
function search() {
    var data = form.val("formTest");
    var trueName = $("input[name=trueName]").val();
    console.log(data.remark);
    console.log(data.type);
    console.log(data.createDate);
    getData(trueName, data.remark, data.type, data.createDate);
}

//删除
function del(id) {
    console.log(id)
    $.ajax({
        url: '/microcircle/delLog',
        type: 'post',
        dataType: 'json',
        data: {'logId': id},
        success: function (item) {
            if (item.data){
                layer.msg('删除成功');
                getData('', '', '', '');
            } else {
                layer.msg('删除失败');
            }
        }
    })
}